package org.rjxh.examfront.comtroller;

import io.netty.util.internal.StringUtil;
import org.rjxh.examfront.pojo.ExamUser;
import org.rjxh.examfront.pojo.R;
import org.rjxh.examfront.service.ExamUserLoginService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/user")
public class LoginController {
    @Resource
    private ExamUserLoginService examUserLoginService;

    @PostMapping("/login")
    public R login(@RequestBody ExamUser examUser) {
        if (
                StringUtil.isNullOrEmpty(examUser.getUserName())
                        || StringUtil.isNullOrEmpty(examUser.getPassword())
        ) {
            return new R(200, "用户名或密码错误");
        }
        return examUserLoginService.login(examUser);
    }

    @PostMapping("/logout")
    public R logout(@RequestBody ExamUser examUser) {
        return examUserLoginService.logout(examUser);
    }
}
